package com.sskj.lib.util;

import android.text.TextUtils;

import com.sskj.common.util.NumberUtil;
import com.sskj.lib.BaseHttpConfig;
import com.sskj.lib.Constans;

import java.math.BigDecimal;
import java.time.chrono.IsoChronology;

public class CommonUtil {
    /**
     * 处理钱包地址
     *
     * @param wallet
     * @return
     */
    public static String dealWallet(String wallet) {
        if (wallet == null) {
            return "";
        }
        String start = wallet.substring(0, 6);
        String end = wallet.substring(wallet.length() - 6, wallet.length());
        return start + "******" + end;
    }

    /**
     * 处理币种金额
     *
     * @param money
     * @return
     */
    public static String dealCoin(String money) {
        if (TextUtils.isEmpty(money)) {
            return "0.0000";
        }
        return NumberUtil.keep(money, 4);
    }

    /**
     * 处理人民币金额
     *
     * @param money
     * @return
     */
    public static String dealCNY(String money) {
        if (TextUtils.isEmpty(money)) {
            return "0.00";
        }
        return NumberUtil.keep(money, 2);
    }

    /**
     * 处理交易号 0x53c845d04d5a2aee3212a2554ed1e378e27b63cb36eeac0d4ebdb48c5c9af20b
     */

    public static String dealTradeNum(String tradeNum) {
        if (tradeNum == null) {
            return "";
        }
        if (tradeNum.length() < 9) {
            return "--";
        }
        String start = tradeNum.substring(0, 8);
        String end = tradeNum.substring(tradeNum.length() - 8, tradeNum.length());
        return start + "********" + end;
    }

    /**
     * 处理手机号
     */

    public static String dealTel(String tel) {
        if (tel == null) {
            return "";
        }
        if (tel.length() < 11) {
            return "--";
        }
        String start = tel.substring(0, 3);
        String end = tel.substring(tel.length() - 4, tel.length());
        return start + "****" + end;
    }

    public static String dealImg(String url) {
        return BaseHttpConfig.BASE_URL + url;
    }

    public static String dealPlus(String tel) {
        if (tel == null) {
            return "";
        }
        if (tel.length() == 1) {
            return tel;
        }
        if (tel.charAt(0) == '-') {
            return tel;
        } else {
            return "+" + tel;
        }

    }

    /**
     * 处理加元与美元
     *
     * @param usdt
     * @return
     */
    public static String dealMoney(String usdt) {
        if (Constans.DANWEI.equals("$")) {
            return NumberUtil.keepNoZero(usdt);
        } else {
            String usdtC = new BigDecimal(usdt).multiply(new BigDecimal(Constans.RATE)).toPlainString();
            return NumberUtil.keepNoZero(usdtC);
        }
    }

    /**
     * BTC ETH保留3位小数，CUSD / MCAD保留4位小数，MPC  / MXT保留4位去掉无效0，
     * 折合 C$ / $ 都保留2位，
     * 涨跌幅两位小数，
     * 持有数量5位小数，
     *
     * @param money    金额
     * @param coinName 币种
     * @return
     */
    public static String dealCoinNum(String money, String coinName) {
        if (TextUtils.isEmpty(money)) {
            money = "0";
        }
        if (coinName.equals(Constans.COIN_LTC) || coinName.equals(Constans.COIN_ETH)) {
            return NumberUtil.keep(money, 6);
        } else if (coinName.equals(Constans.COIN_CNY) || coinName.equals(Constans.COIN_AICASH)) {
            return NumberUtil.keep2(money);
        } else if (coinName.equals(Constans.COIN_USDT)) {
            return NumberUtil.keep4(money);
        } else if (coinName.equals(Constans.COIN_BTC)) {
            return NumberUtil.keep(money, 8);
        }
        return "";
    }

}
